package com.wn.ziroom.config;

import com.wn.ziroom.utils.JacksonUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.serializer.RedisSerializationContext;

import java.time.Duration;

@Configuration
public class RedisConfig {

    @Bean
    public RedisCacheConfiguration redisCacheConfiguration() {
        RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig();
        // 设置序列化的方式，并设置所有Key的TTL为2小时
        configuration = configuration.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(JacksonUtil.getJackson2Redis()))
                .entryTtl(Duration.ofHours(2));
        return configuration;
    }
}
